package com.huazai.out_school_manager.Servlet;


import com.huazai.out_school_manager.Service.UserService;
import com.huazai.out_school_manager.Service.realization.UserServiceReal;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet(name = "register", value = "/register")
public class RegisterServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String userid = request.getParameter("userid");
        String password = request.getParameter("password");
        String field = request.getParameter("field");

//        System.out.println("username = " + username);
//        System.out.println("userid = " + userid);
//        System.out.println("password = " + password);
//        System.out.println("field= " + field);


        UserService userService = new UserServiceReal();
        String mes = userService.doRegister(username, password,userid, field, request);

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = response.getWriter();
        pw.print("<h1 align=\"center\">" + mes + "</h1>");
    }
}
